<?php
namespace app\common\controller;
use app\common\controller\All;
class Home extends All{
    public function __construct(){
        parent::__construct();
		
        $this->Lable_Style();
    }
	//搜索变量定义
	public function Lable_Search(){
		$param = zanpiancms_param_url();	
		if($param['sid']){
		    $model=$GLOBALS['config']['model'][$param['sid']];				
		    $array_search['search_skin']='search_'.$model['name'];
		}else{
			$array_search['search_skin']='search';
		}
		$array['cid'] = $param['cid'];
		$array['actor'] = $param['actor'];
		$array['director'] = $param['director'];			
		$array['area'] = $param['area'];
		$array['langaue'] = $param['langaue'];
		$array['year'] = $param['year'];
		$array['wd'] = $param['wd'];
		$array['name'] = $param['name'];
		$array['title'] = $param['title'];
		$array['letter'] = $param['letter'];
		$array['order'] = $param['order'];
		$array['p'] = $param['p'];
		$this->assign('url',zanpian_url($GLOBALS['route'],array('wd'=>urlencode(trim($param['wd'])),'p'=>$param['p'])));
        $this->assign('param',$array);			
		return $array_search;
    }	
	//栏目页变量定义
	public function Lable_List($param){
        $list=F('_data/list_all');		
		$array_list=$list[$param['id']];
		if(!$array_list){		   
		   return abort(404,'没有找到相关分类');
		}		
		$replace=$this->Lable_Replace($array_list);
		if($array_list['list_title']){
		    $array_list['list_title']=str_replace($replace['find'],$replace['replace'],$array_list['list_title']);
		}
		if($array_list['list_keywords']){
		    $array_list['list_keywords']=str_replace($replace['find'],$replace['replace'],$array_list['list_keywords']);
		}
		if($array_list['list_description']){
		    $array_list['list_description']=str_replace($replace['find'],$replace['replace'],$array_list['list_description']);
		}
        if($GLOBALS['route']=='home/vod/type'){	
            config('params',array('id'=>$param['id'],'dir'=>$param['dir'],'mcid'=>$param['mcid'],'mename'=>$param['mename'],'area'=>$param['area'],'earea'=>$param['earea'],'year'=>$param['year'],'letter'=>$param['letter'],'order'=>$param['order'],'p'=>'[PAGE]'));	
            $url_param=array('id'=>$param['id'],'dir'=>$param['dir'],'mcid'=>$param['mcid'],'mename'=>$param['mename'],'area'=>$param['area'],'earea'=>$param['earea'],'year'=>$param['year'],'letter'=>$param['letter'],'order'=>$param['order'],'p'=>$param['p']);	
		}elseif($GLOBALS['route']=='home/star/type'){
			config('params',array('id'=>$param['id'],'dir'=>$param['dir'],'sex'=>$param['sex'],'zy'=>$param['zy'],'area'=>$param['area'],'letter'=>$param['letter'],'order'=>$param['order'],'p'=>'[PAGE]'));
			$url_param=array('id'=>$param['id'],'dir'=>$param['dir'],'sex'=>$param['sex'],'zy'=>$param['zy'],'area'=>$param['area'],'letter'=>$param['letter'],'order'=>$param['order'],'p'=>$param['p']);	
		}else{
			config('params',array('id'=>$param['id'],'dir'=>$param['dir'],'p'=>'[PAGE]'));
			$url_param=array('id'=>$param['id'],'dir'=>$param['dir'],'p'=>$param['p']);
		}
		$this->assign('url',zanpian_list_url($GLOBALS['route'],$url_param));
        $this->assign('param',$param);		
		$this->assign('show',$array_list);
        return $array_list ;	
    }
	//视频处理
	public function Lable_Vod_Read($array,$sid){
        $data=$this->Lable_Read($array,$sid);
		$array_list=$data['show'];
		$array=$data['read'];		
        $urls = $this->playlist_all($array);
		//print_r($urls);
		unset($array['vod_url']);
		$array['vod_play_list']=$urls['vod_play_list'];
		$array['vod_down_list']=$urls['vod_down_list'];
		if($array['vod_copyright']==1){
			$array['vod_copyright_txt']=$GLOBALS['config']['video']['video_copyright'];
		}
		if(!empty($array_list['list_pid'])){
		   $list=F('_data/list_all');
		   $array_big_list=$list[$array_list['list_pid']];
		   if(!empty($array_big_list['list_vipplay'])){
			   $array['vod_play_vip']=$array_big_list['list_vipplay']; 
		   }
		   if(!empty($array_big_list['list_play'])){
			   $array['vod_play_pay']=$array_big_list['list_play']; 
		   }
		   if(!empty($array_big_list['list_trysee'])){
			   $array['vod_play_trysee']=$array_big_list['list_trysee']; 
		   }		   
		}
		if(!empty($array_list['list_vipplay'])){
			$array['vod_play_vip']=$array_list['list_vipplay']; 
		}
		if(!empty($array_list['list_play'])){
			$array['vod_play_pay']=$array_list['list_play']; 
		}
		if(!empty($array_list['list_trysee'])){
			$array['vod_play_trysee']=$array_list['list_trysee']; 
		}
		if(!empty($array['vod_vipplay'])){
			$array['vod_play_vip']=$array['vod_vipplay']; 
		}
		if(!empty($array['vod_pay'])){
			$array['vod_play_pay']=$array['vod_pay']; 
		}
		if(!empty($array['vod_trysee'])){
			$array['vod_play_trysee']=$array['vod_trysee']; 
		}	
        $arrays['show'] = $array_list;
        $arrays['read'] = $array;	
		return $arrays;
    }
	public function Lable_Vod_Play($param='',$array,$vip=''){
		if(empty($param)){
		   $param = zanpiancms_param_url();
		}
		$authcode = new \com\Code();
		$auth = md5('plain-'.md5(date('Y-m-d-H').$param['id'].'_'.$param['pid']));  // 加密密钥
        $player_info=$array['read']['vod_play_list'][$param['sid']];	
		$player_urls=$array['read']['vod_play_list'][$param['sid']]['play_urls'][$param['pid']];
		if(empty($player_urls)){
			abort(404,'内容不存在');
		}
		$array['read']['player_name']=$player_info['player']['play_name'];
		$array['read']['player_title']=$player_info['player']['play_title'];
		$array['read']['player_sort']=$player_info['player']['player_sort'];
		$array['read']['player_copyright']=$player_info['player']['play_copyright'];
		// 解析服务器变量处理
		if($GLOBALS['config']['video']['player_api']){
			$array['read']['player_apiurl'] = str_replace('{playname}',$array['play_name'],$GLOBALS['config']['video']['player_api']);
		}
		if($player_info['player']['play_apiurl']){
			$array['read']['player_apiurl'] = str_replace('{playname}',$array['play_name'],$player_info['player']['play_apiurl']);
		}		
		$array['read']['player_cloud']=$player_info['player']['play_cloud'];
		$array['read']['player_width']=$GLOBALS['config']['video']['player_width'];
		$array['read']['player_height']=$GLOBALS['config']['video']['player_height'];
		$array['read']['player_second']=$GLOBALS['config']['video']['player_second'];
		$array['read']['player_loading']=$GLOBALS['config']['video']['player_loading'];
		$array['read']['play_count']=count($array['read']['vod_play_list'][$param['sid']]['play_urls']);
		$array['read']['play_sid']=$player_urls['sid'];
		$array['read']['play_pid']=$player_urls['pid'];
		$array['read']['play_name']=$player_urls['name'];
		// $array['read']['play_path']=$player_urls['path'];
		$array['read']['play_path'] = base64_encode($authcode->authcode($player_urls['path'],"ENCODE",$auth, 0));
		$array['read']['play_auth'] = $auth;
		$array['read']['play_prev_path']=$array['read']['vod_play_list'][$param['sid']]['play_urls'][$param['pid']-1]['path'];
        $array['read']['play_next_path']=$array['read']['vod_play_list'][$param['sid']]['play_urls'][$param['pid']+1]['path'];	
		//播放器调用
		if(empty($vip)){
		    if((!empty($array['read']['vod_play_vip']) || !empty($array['read']['vod_play_pay']))){//付费与注册用户点播
			    $array['read']['vod_player'] = '<div id="zanpiancms-player-vip"><div class="zanpiancms-player-box">影片需验证观看权限，请稍等。</div><iframe class="zanpiancms-player-iframe" src="'.url('home/vod/vip',array('type'=>'play','id'=>$array['read']['vod_id'],'sid'=>$param['sid'],'pid'=>$param['pid'])).'" width="100%" height="100%" frameborder="0"></iframe></div>';
		    }else{
			    $array['read']['vod_player'] = $this->zanpiancms_player($array['read']);
		    }
		}else{
			$array['read']['vod_player'] = $this->zanpiancms_player($array['read']);
		}
		$replace=$this->Lable_Replace($array['show'],$array['read']);
		if(!empty($array['show']['list_pid'])){
		   $list=F('_data/list_all');
		   $array_big_list=$list[$array['show']['list_pid']];
		  	if(!empty($array_big_list['list_play_title'])){
		       $array['read']['vod_play_title']=str_replace($replace['find'],$replace['replace'],$array_big_list['list_play_title']);
		    }
		    if(!empty($array_big_list['list_play_keywords'])){
		       $array['read']['vod_play_keywords']=str_replace($replace['find'],$replace['replace'],$array_big_list['list_play_keywords']);
		    }
		    if(!empty($array_big_list['list_play_description'])){
		       $array['read']['vod_play_description']=str_replace($replace['find'],$replace['replace'],$array_big_list['list_play_description']);
		    }
		    if(!empty($array_big_list['list_skin_play'])){
		       $array['read']['vod_skin_play']=$array_big_list['list_skin_play'];
		    }			
		}		
		if(!empty($array['show']['list_play_title'])){
		    $array['read']['vod_play_title']=str_replace($replace['find'],$replace['replace'],$array['show']['list_play_title']);
		}
		if(!empty($array['show']['list_play_keywords'])){
		    $array['read']['vod_play_keywords']=str_replace($replace['find'],$replace['replace'],$array['show']['list_play_keywords']);
		}
		if(!empty($array['show']['list_play_description'])){
		    $array['read']['vod_play_description']=str_replace($replace['find'],$replace['replace'],$array['show']['list_play_description']);
		}
		if(!empty($array['show']['list_skin_play'])){
		       $array['read']['vod_skin_play']=$array['show']['list_skin_play'];
		}	
		//if($GLOBALS['config']['video']['video_play']==1 || $array['read']['vod_copyright']==2){
		//	$array['read']['vod_skin_play'] = !empty($array['read']['vod_skin_play']) ? $array['read']['vod_skin_play'].'_blank' : 'vod_play_blank';
		//}else{
			$array['read']['vod_skin_play'] = !empty($array['read']['vod_skin_play']) ? $array['read']['vod_skin_play'] : 'vod_play';	
		//}	
//print_r($array);
        $this->assign('url',zanpian_play_url($array['read'],$param));		
		return $array;		

	}
    public function zanpiancms_player($array){
		if($GLOBALS['config']['video']['video_play']==1 || $array['vod_copyright']==2){
           $array['player_name']='jump';
        }			
		if(!empty($GLOBALS['config']['video']['player_cloud']) && empty($array['player_cloud'])){
			return '<script src="'.$GLOBALS['config']['video']['player_cloud'].'?url='.base64_encode($array['play_path']).'&name='.$array['player_name'].'&co='.$array['player_copyright'].'&api='.base64_encode($array['player_apiurl']).'&time='.$array['player_second'].'&ad='.base64_encode($array['player_loading']).'&next='.base64_encode($array['play_next_path']).'"></script>'."\n";
		}else{
            $data = array();
			$data['player'] = TPL_PATH;
			$data['url'] = $array['play_path'];
			$data['next'] = $array['play_pid']==$array['play_count'] ? '' : zanpian_play_url($array,array('sid'=>$array['play_sid'],'pid'=>$array['play_pid']+1),true,true);
			$data['name'] = !empty($array['player_copyright']) ? 'copyright' : $array['player_name'];
			$data['apiurl'] = $array['player_apiurl'];
			$data['adtime'] = $array['player_second'];
			$data['adurl'] =  $array['player_loading'];
			$data['copyright'] = $array['player_copyright'];
			return '<script>var zanpiancms_player = '.json_encode($data).';</script>'."\n".'<script src="'.TPL_PATH.'player/'.$data['name'].'.js"></script>';			
		
		}	
    }	
	//组合播放地址组列表为二维数组
	public function playlist_all($array){
		if(empty($array['vod_url'])){return false;}
		$array_player = explode('$$$',$array['vod_play']);
		$array_urllist = explode('$$$',$array['vod_url']);
		$config_player = $GLOBALS['config']['play'];
		foreach ($array_player as $key=>$value){
		  //提取下载播放组
          if(substr($value,0,4) == 'down'){
		        $array_down_player[$key] = $value;
		        $array_down_urllist[$key]=$array_urllist[$key];	  
          }				
		  //过滤不存在以及禁用的播放器	
          if(empty($config_player[$value]) || $config_player[$value]['play_display']==0 || substr($value,0,4) == 'down'){
            unset($array_player[$key]);
		    unset($array_urllist[$key]);
          }	
		}
		$array_player=array_values($array_player);
		$array_urllist=array_values($array_urllist);
		$playlist = array();
		foreach($array_player as $k=>$val){
			$urls = $this->playlist_one($array_urllist[$k],$val,$k+1);
		    $player_info = $config_player[$val];
			$playlist[$k + 1] = [
			    'player' => $player_info,
				'player_sort' => $player_info['play_oid'],
                'play_sid' => $k + 1,
				'play_title' => $player_info['play_title'],
                'play_name' => $val,
                'play_count' => count($urls),
                'play_urls' => $urls,
            ];
        }
		if(empty($array['vod_playoid']) || empty($GLOBALS['config']['video'])){
			array_multisort(array_column($playlist,'player_sort'),SORT_ASC,$playlist);
            $art=[];
            foreach($playlist as $k=>$v){
                $tmp[$v['play_sid']] = $v;
            }
            $playlist = $tmp;			
		}
		if($array_down_player && $array_down_urllist){
		    $array_down_player=array_values($array_down_player);
		    $array_down_urllist=array_values($array_down_urllist);	
            $downlist = array();
		    foreach($array_down_player as $k=>$val){
			    $urls = $this->playlist_one($array_down_urllist[$k],$val,$k+1);
		        $player_info = $config_player[$val];
			    $sort[] = $player_info['play_oid'];
			    $downlist[$k + 1] = [
			        'player' => $player_info,
				    'player_oid' => $player_info['play_oid'],
                    'play_sid' => $k + 1,
				    'play_title' => $player_info['play_title'],
                    'play_name' => $val,
                    'play_count' => count($urls),
                    'play_urls' => $urls,
                ];
            }			
		}
	    return ['vod_play_list'=>$playlist,'vod_down_list'=>$downlist];
	}
	
	//分解单组播放地址链接
	public function playlist_one($url,$play,$sid){
	    $array_url = explode(chr(13),str_replace(array("\r\n", "\n", "\r"),chr(13),$url));
		foreach($array_url as $key=>$val){
			$urllist[$key+1]['sid'] = $sid;
			$urllist[$key+1]['pid'] = $key+1;
		    if (strpos($val,'$') > 0) {
		        $ji = explode('$',$val);
			    $urllist[$key+1]['name'] = trim($ji[0]);
				$urllist[$key+1]['path']=	trim($ji[1]);
				$urllist[$key+1]['pic'] = trim($ji[2]);	
				$urllist[$key+1]['fen'] = trim($ji[3]);
				$urllist[$key+1]['miao'] = trim($ji[4]);
				$urllist[$key+1]['source'] = trim($ji[5]);				
			}else{
			    $urllist[$key+1]['name'] = '第'.($key+1).'集';
				$urllist[$key+1]['path']=	trim($val);
			}
		}
	    return $urllist;
	}
	//明星处理
	public function Lable_Story_Read($array,$sid){
        $data=$this->Lable_Read($array,$sid);
		$array_list=$data['show'];
		$array=$data['read'];
        $urls = $this->playlist_all($array);
		unset($array['vod_url']);
		$array['vod_play_list']=$urls['vod_play_list'];
		$array['vod_down_list']=$urls['vod_down_list'];
        $arrays['show'] = $array_list;
        $arrays['read'] = $array;	
		return $arrays;
    }	
	//明星处理
	public function Lable_Star_Read($array,$sid){
        $data=$this->Lable_Read($array,$sid);
		$array_list=$data['show'];
		$array=$data['read'];
		if(!empty($array['star_guanxi'])){
		    $guanxiarray=explode(',',$array['star_guanxi']);
		    foreach($guanxiarray  as $key=>$val){
		        $gx=explode('@',$val);	
			    $guanxi[$key]['title']=	$gx[0];
		        $guanxi[$key]['name']=	$gx[1];
		        $guan[$gx[1]]=$gx[0];
			    $xi[$key]=$gx[1];
		    }
		    $array['star_guanxi']=$guanxi;
		    $array['star_guan']=$guan;
		    $array['star_xi']=implode(',',$xi);			
		}
        if(!empty($array['star_info'])){		 
		foreach(explode('||',$array['star_info']) as $k=>$val){
				$info=explode('@@',$val);
			    $array['star_data'][$k]['title']=$info[0];
				$array['star_data'][$k]['info']=$info[1];
			}				 
        }
		unset($array['star_info']);			
        $arrays['show'] = $array_list;
        $arrays['read'] = $array;		
		return $arrays;
    }		
	//节目处理
	public function Lable_Tv_Read($array,$sid,$cai=''){
        $data=$this->Lable_Read($array,$sid);
		$array_list=$data['show'];
		$array=$data['read'];
		$date=date("Y年m月d日");
		$time=strtotime(date("H:i"));
		$weeklist = array('星期一'=>1,'星期二'=>2,'星期三'=>3,'星期四'=>4,'星期五'=>5,'星期六'=>6,'星期日'=>7);
		$week=str_replace('0','7',date("w"));
		if(empty($cai) && !empty($array['tv_uptime']) && time() - $array['tv_lasttime'] > 3600*$array['tv_uptime'] && !empty($array['tv_apiid']) && !empty($array['tv_apitype'])){
            $apiurl=F('_data/caiji_api');
			$get_data=zanpian_curl_get('http://'.$apiurl[array_rand($apiurl)].'/zanpiancmsv9/jiemu.php?id='.$array['tv_apiid'].'&type='.$array['tv_apitype']);
			$data=json_decode($get_data,true);
			if($data['code']==1){
				$data['tv_id']=$array['tv_id'];
				$data['tv_letters']=$array['tv_letters'];
				$save['tv_data']=$data['data'];
				$save['tv_lasttime']=time();
				model('tv')->save($save,array('tv_id' => $array['tv_id']));
				$array['tv_data']=$data['data'];
			}else{
			    $array['tv_data']=json_decode($array['tv_data'],true);
			}	
		}else{
		    $array['tv_data']=json_decode($array['tv_data'],true);
		}
		if(!empty($array['tv_data'])){
		foreach($array['tv_data'] as $key=>$value){
			if($date==$value['date']){
				$array['tv_week_list'][$weeklist[$value['week']]]['day']=1;
			}
			if($week==$weeklist[$value['week']]){
				$array['tv_week_list'][$weeklist[$value['week']]]['cut']=1;
			}			
			$array['tv_week_list'][$weeklist[$value['week']]]['week']=$value['week'];
			$array['tv_week_list'][$weeklist[$value['week']]]['date']=$value['date'];
			$array['tv_week_list'][$weeklist[$value['week']]]['wid']=$weeklist[$value['week']];
	        $datas=explode(chr(13),trim($value['data']));
		    $len = count($datas);
			foreach($datas as $k=>$val){
				$array['tv_datalist'][$weeklist[$value['week']]]['week']=$value['week'];
			    $array['tv_datalist'][$weeklist[$value['week']]]['date']=$value['date'];
				$datalist=explode('$',$val);
		        $ndatalist=explode('$',$datas[$k+1]);
				if($date==$value['date'] && $time >= strtotime($datalist[0]) && $time < strtotime($ndatalist[0]) || $date==$value['date'] && $time >= strtotime($datalist[0]) && $k == $len-1){
				    $array['tv_datalist'][$weeklist[$value['week']]]['data'][$k]['live']=1;
				}elseif($week==$weeklist[$value['week']] && $time >= strtotime($datalist[0]) && $time < strtotime($ndatalist[0]) || $date==$value['date'] && $time >= strtotime($datalist[0]) && $k == $len-1){
					$array['tv_datalist'][$weeklist[$value['week']]]['data'][$k]['live']=1;
				}
				$array['tv_datalist'][$weeklist[$value['week']]]['data'][$k]['time']=$datalist[0];
				$array['tv_datalist'][$weeklist[$value['week']]]['data'][$k]['name']=str_replace('#','',$datalist[1]);
		        $datalistkey[$k]=explode('#',$datalist[1]);
		        if(count($datalistkey[$k])>1){
			        $array['tv_datalist'][$weeklist[$value['week']]]['data'][$k]['keywords']=$datalistkey[$k][1];	
		        }else{
			        $array['tv_datalist'][$weeklist[$value['week']]]['data'][$k]['keywords']=preg_replace(array("/.*?:/","/(\(.*?)\)/","/.*?：/","/（(.*?)）/","/\d*/"),"",$datalist[1]);
		        }				
			}
			
		}
		}
		unset($array['tv_data']);
        $arrays['show'] = $array_list;
        $arrays['read'] = $array;		
		return $arrays;
    }	
	//新闻内容
	public function Lable_News_Read($array,$param){
        $data=$this->Lable_Read($array,2);
		$array_list=$data['show'];
		$array=$data['read'];
		$array['news_page_key'] = 1;
		//统计内容中图片个数
		$array['news_images_array']  = zanpian_content_image_array($array['news_content']);
		$array['news_images_count'] = count($array['news_images_array']);
		$array_content = preg_split("/#zanpianpage#/", $array['news_content']);
		//是否存在数字分页
		if(count($array_content)>1){	
		    $array['news_detail_page_count'] = count($array_content);
			foreach($array_content as $key=>$value){
			    $key=$key+1;	
			    $array['news_detail_page'][$key]['news_content'] = $value;
		        $array['news_detail_page'][$key]['news_pagelist']=$this->news_page_url('home/news/read',array('id'=>$array['news_id'],'cid'=>$array['news_cid'],'dir'=>$array_list['list_dir'],'p'=>"zanpianpage",'jumpurl'=>$array['news_jumpurl']),$key,$array['news_detail_page_count'],3);//数字分页	
			    $array['news_detail_page'][$key]['news_page']=$key;
			}
			$array['news_page_key'] = $array['news_detail_page_count'];
			unset($array['news_images_array'],$array['news_content'],$array['news_images_count']);			
		}
		//内容模式为图片分页
		elseif($array['news_mid']==2 && $array['news_images_count']>1){
			foreach($array['news_images_array'] as $key=>$value){
			    $key=$key+1;	  
			    if($key==1){	
			        $array['news_images'][$key]['news_content']  = zanpian_content_filter_image($array['news_content']);
			    }			  
		        $array['news_images'][$key]['news_content_image']=$value;
			    $array['news_images'][$key]['news_pageprev']  = $this->news_page_prev('home/news/read',array('id'=>$array['news_id'],'cid'=>$array['news_cid'],'dir'=>$array_list['list_dir'],'p'=>"zanpianpage",'jumpurl'=>$array['news_jumpurl']),$key,$array['news_images_count'],3);
			    $array['news_images'][$key]['news_pagenext']  = $this->news_page_next('home/news/read',array('id'=>$array['news_id'],'cid'=>$array['news_cid'],'dir'=>$array_list['list_dir'],'p'=>"zanpianpage",'jumpurl'=>$array['news_jumpurl']),$key,$array['news_images_count'],3);
		        $array['news_images'][$key]['news_pagelist']=$this->news_page_url('home/news/read',array('id'=>$array['news_id'],'cid'=>$array['news_cid'],'dir'=>$array_list['list_dir'],'p'=>"zanpianpage",'jumpurl'=>$array['news_jumpurl']),$key,$array['news_images_count'],3);//数字分页
			    $array['news_images'][$key]['news_page']=$key;
			}
            $array['news_page_key'] = $array['news_images_count'];			
            unset($array['news_images_array'],$array['news_content']);     			
		}
		//内容模式为图片幻灯
		elseif($array['news_mid']==1){
			if($array['news_images_count']>=$GLOBALS['config']['system']['system_news_images']){
				$array['news_slide_count']=$array['news_images_count'];
				$array['news_slide']  = $array['news_images_array'];	
			    $array['news_content'] = zanpian_content_filter_image($array['news_content']);
				unset($array['news_images_array'],$array['news_images_count']); 
			}else{
			    $array['news_content']  = $array['news_content'];	  
			    unset($array['news_slide_count'],$array['news_slide']);  
			}
		}
        if(!empty($array['news_playname']) && !empty($array['news_playurl'])){
		    $player = F('_play/play_status');
            $news_player=$player[$array['news_playname']];
            // 解析服务器变量处理
		    if($news_player['player_apiurl']){
			    $array['play_apiurl'] = str_replace('{playname}',$array['news_playname'], $news_player['player_apiurl']);
		    }elseif(trim($GLOBALS['config']['video']['player_api'])){
			    $array['play_apiurl'] = str_replace('{playname}',$array['news_playname'], trim($GLOBALS['config']['video']['player_api']));
		    }
            if(!empty($news_player['play_cloud']) || empty($GLOBALS['config']['video']['player_cloud']) || empty($GLOBALS['config']['video']['player_cloud']) && empty($news_player['play_cloud'])){
			    $data = array();
				$data['player'] = TPL_PATH;
			    $data['url'] = $array['news_playurl'];
			    $data['name'] = empty($array['news_playname']) ? "copyright" : $array['news_playname'];
			    $data['apiurl'] = $array['play_apiurl'];
			    $data['width'] = $GLOBALS['config']['video']['player_width'];
			    $data['height'] = $GLOBALS['config']['video']['player_height'];
			    $data['adtime'] = $GLOBALS['config']['video']['player_second'];
			    $data['adurl'] =  $GLOBALS['config']['video']['player_playad'];
			    $array['news_player'] = '<script>var zanpiancms_player = '.json_encode($data).';</script><script src="'.TPL_PATH.'player/'.$data['name'].'.js"></script>';
			    unset($data);				
		    }else{
		        $array['news_player'] = '<script src="'.$GLOBALS['config']['video']['player_cloud'].'?url='.base64_encode($array['news_playurl']).'&name='.$array['news_playname'].'&co=&api='.base64_encode($array['play_apiurl']).'&time='.$GLOBALS['config']['video']['player_second'].'&ad='.base64_encode($GLOBALS['config']['video']['player_playad']).'"></script>'."\n";
			
		    }
		}		
		$arrays['show'] = $array_list;
		$arrays['read'] = $array;
		$array['p']=$param['p'];
        $this->assign('url',zanpian_read_url($GLOBALS['route'],$array));		
        return $arrays;
    }
	//内容处理
	public function Lable_Read($array,$sid){
        $list=F('_data/list_all');
        $model=$GLOBALS['config']['model'][$sid];		
		$array_list=$list[$array[$model['name'].'_cid']];
		//判断是否存上级分类
		if($array_list['list_pid']){
		   $array_big_list=$list[$array_list['list_pid']];	
		}
		if(!empty($array_big_list['list_skin_detail'])){
		    $array[$model['name'].'_skin_detail'] = trim($array_big_list['list_skin_detail']);
		}
		if(!empty($array_list['list_skin_detail'])){
		    $array[$model['name'].'_skin_detail'] = trim($array_list['list_skin_detail']);
		}		
		if(!empty($array[$model['name'].'_skin'])){
			$array[$model['name'].'_skin_detail'] = trim($array[$model['name'].'_skin']);
		}
		$replace=$this->Lable_Replace($array_list,$array);
		if($sid==1){
		    if(empty($array[$model['name'].'_stitle'])){
			    if($array_big_list['list_detail_title']){
		            $array[$model['name'].'_stitle']=str_replace($replace['find'],$replace['replace'],$array_big_list['list_detail_title']);
			    }
			    if($array_list['list_detail_title']){
			        $array[$model['name'].'_stitle']=str_replace($replace['find'],$replace['replace'],$array_list['list_detail_title']);
			    }
		    }			
		}else{
		    if(empty($array[$model['name'].'_title'])){
			    if($array_big_list['list_detail_title']){
		            $array[$model['name'].'_title']=str_replace($replace['find'],$replace['replace'],$array_big_list['list_detail_title']);
			    }
			    if($array_list['list_detail_title']){
			        $array[$model['name'].'_title']=str_replace($replace['find'],$replace['replace'],$array_list['list_detail_title']);
			    }
		    }
		}
		if(empty($array[$model['name'].'_keywords'])){
			if($array_big_list['list_detail_keywords']){
		    $array[$model['name'].'_keywords']=str_replace($replace['find'],$replace['replace'],$array_big_list['list_detail_keywords']);
			}
			if($array_list['list_detail_keywords']){
			$array[$model['name'].'_keywords']=str_replace($replace['find'],$replace['replace'],$array_list['list_detail_keywords']);
			}
		}
		if(empty($array[$model['name'].'_description'])){
			if($array_big_list['list_detail_description']){
		    $array[$model['name'].'_description']=str_replace($replace['find'],$replace['replace'],$array_big_list['list_detail_description']);
			}
			if($array_list['list_detail_description']){
			$array[$model['name'].'_description']=str_replace($replace['find'],$replace['replace'],$array_list['list_detail_description']);
			}
		}
		if($sid==4){
		    if(empty($array[$model['name'].'_part_title'])){
			    if($array_big_list['list_play_title']){
		            $array[$model['name'].'_part_title']=str_replace($replace['find'],$replace['replace'],$array_big_list['list_play_title']);
			    }
			    if($array_list['list_play_title']){
			        $array[$model['name'].'_part_title']=str_replace($replace['find'],$replace['replace'],$array_list['list_play_title']);
			    }
		    }		
		    if(empty($array[$model['name'].'_part_keywords'])){
			    if($array_big_list['list_play_keywords']){
		            $array[$model['name'].'_part_keywords']=str_replace($replace['find'],$replace['replace'],$array_big_list['list_play_keywords']);
			    }
			    if($array_list['list_play_keywords']){
			        $array[$model['name'].'_part_keywords']=str_replace($replace['find'],$replace['replace'],$array_list['list_play_keywords']);
			    }
		    }
		    if(empty($array[$model['name'].'_part_description'])){
			    if($array_big_list['list_play_description']){
		            $array[$model['name'].'_part_description']=str_replace($replace['find'],$replace['replace'],$array_big_list['list_play_description']);
			    }
			    if($array_list['list_play_description']){
			        $array[$model['name'].'_part_description']=str_replace($replace['find'],$replace['replace'],$array_list['list_play_description']);
			    }
		    }
		}		
		$arrays['show'] = $array_list;
		$arrays['read'] = $array;
        $this->assign('url',zanpian_read_url($GLOBALS['route'],$array));		
        return $arrays;
    }		
	public function Lable_Replace($list,$info=[]){
		$param = zanpiancms_param_url();
		$page=$param['p']>1 ?'第'.$param['p'].'页':'';
        $data['find']=['{special_name}','{tv_name}','{role_star}','{role_name}','{star_name}','{news_name}','{vod_name}','{vod_aliases}','{vod_title}','{vod_letters}','{vod_actor}','{vod_director}','{vod_content}','{vod_total}','{vod_continu}','{vod_area}','{vod_year}','{story_continu}','{story_name}','{part_name}','{part_title}','{play_name}','{play_title}','{play_pid}','{play_sid}','{player_name}','{player_title}','{list_name}','{list_dir}','{list_big_name}','{list_big_dir}','{page}','{site_name}'];
		$data['replace']=[$info['special_name'],$info['tv_name'],$info['role_star'],$info['role_name'],$info['star_name'],$info['news_name'],$info['vod_name'],$info['vod_aliases'],$info['vod_title'],$info['vod_letters'],$info['vod_actor'],$info['vod_director'],$info['vod_content'],$info['vod_total'],$info['vod_continu'],$info['vod_area'],$info['vod_year'],$info['story_continu'],$info['story_name'],$info['part_name'],$info['part_title'],$info['play_name'],$info['play_title'],$info['play_pid'],$info['play_sid'],$info['player_name'],$info['player_title'],$list['list_name'],$list['list_dir'],getlist($list['list_pid'],'list_id','list_name'),getlist($list['list_pid'],'list_id','list_dir'),$page,$GLOBALS['config']['site']['site_name']];
		return $data;
	}	
    public function news_page_prev($model,$params,$currentPage,$totalPages,$halfPer=5,$url=""){
	    $url = zanpian_list_url($model,$params,true,false);
	    unset($params['p']);
	    $first_url= zanpian_list_url($model,$params,true,false);	
        if($currentPage> 1){
            $linkPage = str_replace('zanpianpage',($currentPage-1),$url);
	    }
        if($currentPage== 2){
            $linkPage = $first_url;
	    }	
        return $linkPage;
    }
    public function news_page_next($model,$params,$currentPage,$totalPages,$halfPer=5,$url=""){
	    $url = zanpian_list_url($model,$params,true,false);
        $linkPage .= ( $currentPage < $totalPages )
        ? str_replace('zanpianpage',($currentPage+1),$url)
        : '';
        return $linkPage;
   }	
	
    public function news_page_url($model,$params,$currentPage,$totalPages,$halfPer=5,$pagego="",$url=""){
	    $url = zanpian_list_url($model,$params,true,false);
	    unset($params['p']);
	    $first_url= zanpian_list_url($model,$params,true,false);
	    if($currentPage== 2){
            $linkPage .='<li class="visible-xs"><a href="'.$first_url.'" class="prev" data="p-1">首页</a></li><li><a href="'.$first_url.'" class="prev" data="p-'.($currentPage-1).'">上一页</a></li>' ;			
	    }elseif($currentPage >1){
	        $linkPage .='<li class="visible-xs"><a href="'.$first_url.'" class="prev" data="p-1">首页</a></li><li><a href="'.str_replace('zanpianpage',($currentPage-1),$url).'" class="prev" data="p-'.($currentPage-1).'">上一页</a></li>' ;		
	    }else{
		    $linkPage .='<li class="disabled visible-xs"><span>首页</span></li><li class="disabled"><span>上一页</span></li>';	
	    }
        $linkPage.='<li class="visible-xs active"><span class="num">'.$currentPage.'/'.$totalPages.'</span></li>';	
        for($i=$currentPage-$halfPer,$i>1||$i=1,$j=$currentPage+$halfPer,$j<$totalPages||$j=$totalPages;$i<$j+1;$i++){
		    //格式化第一页
		    if($i == 1){
			    $linkPage .= ($i==$currentPage)?'<li class="hidden-xs  active"><span>'.$i.'</span></li>':'<li class="hidden-xs"><a href="'.str_replace('zanpianpage',$i,$first_url).'" data="p-'.$i.'">'.$i.'</a></li>'; 
		    }else{
                $linkPage .= ($i==$currentPage)?'<li class="hidden-xs active"><span>'.$i.'</span></li>':'<li class="hidden-xs"><a href="'.str_replace('zanpianpage',$i,$url).'" data="p-'.$i.'">'.$i.'</a></li>'; 
		    }
	    }
	    if($currentPage < $totalPages){
	        $linkPage .=	'<li><a href="'.str_replace('zanpianpage',($currentPage+1),$url).'" class="next pagegbk" data="p-'.($currentPage+1).'">下一页</a></li><li class="visible-xs"><a href="'.str_replace('zanpianpage',$totalPages,$url).'" class="prev" data="p-'.$totalPages.'">尾页</a></li>';
	    }else{
		    $linkPage .=	'<li class="disabled"><span>下一页</span></li><li class="visible-xs disabled"><span>尾页</span></li>';
	    }
		return $linkPage;
    }	




	
}
?>